/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-07-16
 * Time: 11:05
 */

//写一个泛型类   当中有个方法  可以求数组最大值

//泛型类
class Generic<E extends Comparable<E>> {
    public E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            if( max.compareTo(array[i])<0 ) {
                max = array[i];
            }
        }
        return max;
    }
}
//泛型方法
class Generic2 {
    public <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            if( max.compareTo(array[i])<0 ) {
                max = array[i];
            }
        }
        return max;
    }
}
//静态泛型方法
class Generic3 {
    public static <E extends Comparable<E>> E findMax(E[] array) {
        E max = array[0];
        for (int i = 1; i < array.length; i++) {
            if( max.compareTo(array[i])<0 ) {
                max = array[i];
            }
        }
        return max;
    }
}
public class TestGeneric {
    public static void main(String[] args) {
        Double[] array = {1.2,2.3,3.4,4.5};
        double max = Generic3.findMax(array);
        System.out.println(max);
    }
    public static void main2(String[] args) {
        String[] array = new String[]{"hello","bit","world","good"};
        Generic2 generic2 = new Generic2();
        String max = generic2.findMax(array);
        //String max = generic2.<String>findMax(array);
        System.out.println(max);
    }
    public static void main1(String[] args) {
        Integer[] array = new Integer[]{1,2,3,4,5};
        Generic<Integer> generic = new Generic<>();
        int max = generic.findMax(array);
        System.out.println(max);
    }
}
